package com.cangshi.service;

import com.cangshi.dao.UserMapper;
import com.cangshi.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 15c on 2017/4/2.
 */
@Service("UserBean")
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    /**
     * 用于用户通过Telphone注册,用于用户通过Telphone注册，并保留一些信息，比如user_stutus，user_power，user_open_id，user_resgister_time，user_resgister_ip
     *
     * @param user
     * @return 1代表成功
     */
    public int addUserByTelphone(User user) {
        return userMapper.insertUserRegisterByTelphone(user);
    }

    /**
     * 用于用户通过Email注册,用于用户通过Telphone注册，并保留一些信息，比如user_stutus，user_power，user_open_id，user_resgister_time，user_resgister_ip
     *
     * @param user
     * @return 1代表成功
     */
    public int addUserByEmail(User user) {
        return userMapper.insertUserRegisterByEmail(user);
    }

    /**
     * 通过user_Id修改用户的user_stutus，user_power，user_open_id
     *
     * @param user
     * @return
     */
    public int updateUserStatePowerOpenIdByUserId(User user) {
        return userMapper.updateUserStatePowerByPrimaryKey(user);
    }

    /**
     * 通过user_Id修改用户的user_level,user_credit
     *
     * @param user
     */
    public int updateUserLevelCredit(User user) {
        return userMapper.updateUserLevelCreditByPrimaryKey(user);
    }


    /**
     * 用户个人资料信息完善 insert
     *
     * @param user
     */
    public int userInformationInsert(User user) {
        return userMapper.insertSelective(user);

    }

    /**
     * 通过user_Id查询用户user_level,user_credit
     *
     * @param userId
     * @return user对象
     */
    public User selectUserLevelCredit(User userId) {
        return userMapper.selectUserLevelCreditByPrimaryKey(userId);
    }

    /**
     * 通过user_Id查询用户user_state,user_Power
     *
     * @param userId
     * @return
     */
    public User selectUserStatePower(User userId) {
        return userMapper.selectUserStatePowerByPrimaryKey(userId);
    }

    /**
     * 通过telPhone查找用户的userId
     *
     * @param telphone return user对象
     */
    public User selectUserIdByTelphone(User telphone) {
        return userMapper.selectIdByTelPhone(telphone);
    }

    /**
     * 通过telPhone查找用户的userId
     *
     * @param userEmail return user对象
     */
    public User selectUserIdByuserEmail(User userEmail) {
        return userMapper.selectIdByuserEmail(userEmail);
    }

    /**
     * 通过user_id修改重置用户密码
     *
     * @param userId
     * @return 1代表成功
     */
    public int updatePasswordByUserId(User userId) {
        return userMapper.updatePasswordByUserId(userId);
    }

    /**
     * 用于用户完善自己的信息
     *
     * @param user
     * @return 1代表修改成功
     */
    public int updateUserPrivateInfoByUserId(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    /**
     * 通过user_Id查询用户一些基本信息
     *
     * @param userId
     * @return 返回用户对象
     */
    public User selectUserPartInfoByUserId(Integer userId) {
        return userMapper.selectUserPartInfoById(userId);
    }

    public User selectAllUserInfoByUserId(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }
}
